﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using Project.dalSql;
using System.Data.SqlClient;
using System.Web.SessionState;
using WISD.Common;

namespace WISD.CarFriend.Web.Admin.Control
{
    /// <summary>
    /// ReturnVisit 的摘要说明
    /// </summary>
    public class ReturnVisit : IHttpHandler, IReadOnlySessionState
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            var Action = NullHelper.NullProcess<string>(context.Request["Action"], "");
            var ConsumeID = NullHelper.NullProcess<int>(context.Request["ConsumeID"], 0);
            var MemberID = NullHelper.NullProcess<string>(context.Request["MemberID"], "");
            var ReturnVisitType = NullHelper.NullProcess<int>(context.Request["ReturnVisitType"], 1);
            var StartTime = NullHelper.NullProcess<DateTime>(context.Request["StartTime"], DateTime.Parse("1900/1/1"));
            var EndTime = NullHelper.NullProcess<DateTime>(context.Request["EndTime"], DateTime.Parse("1900/1/1"));
            var Complaint = NullHelper.NullProcess<string>(context.Request["Complaint"], "");
            var Result = NullHelper.NullProcess<string>(context.Request["Result"], "");
            var Satisfaction = NullHelper.NullProcess<int>(context.Request["Satisfaction"], 1);
            var Memo = NullHelper.NullProcess<string>(context.Request["Memo"], "");
            var State = NullHelper.NullProcess<int>(context.Request["State"], 1);
            var SendEmployee = NullHelper.NullProcess<string>(context.Request["SendEmployee"], "");
            var Reviser = context.Session["UserCode"].ToString();
            var ReviseDate = System.DateTime.Now;

            int PageSize = NullHelper.NullProcess<int>(context.Request["PageSize"], 0);
            int PageIndex = NullHelper.NullProcess<int>(context.Request["CurrentPage"], 0);
            string Condition = NullHelper.NullProcess<string>(context.Request["Condition"], "");
            int Main = NullHelper.NullProcess<int>(context.Request["Main"], 0);

            //新增信息
            if (Action == "AddEntity")
            {
                WISD.CarFriend.Model.CFModel.T_CF_OA_ReturnVisit model = new Model.CFModel.T_CF_OA_ReturnVisit();
                model.ConsumeID = ConsumeID;
                model.IsComplaint = Satisfaction;
                model.ReturnVisitType = ReturnVisitType;
                model.StartTime = StartTime;
                model.EndTime = EndTime;
                model.Complaint = Complaint;
                model.Result = Result;
                model.Satisfaction = Satisfaction;
                model.Memo = Memo;
                model.State = State;
                model.SendEmployee = SendEmployee;
                model.Reviser = Reviser;
                model.ReviseDate = ReviseDate;
                model.Memo1 = "";
                model.Memo2 = "";
                model.Memo3 = "";
                model.Memo4 = "";
                model.Memo5 = "";
                model.Memo6 = "";
                model.Memo7 = "";
                model.Memo8 = "";

                if (BLL.OA.ReturnVisitModule.AddEntity(model).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (Action.Equals("DeleteEntity"))
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.DeleteEntity(Main.ToString()));
                context.Response.End();
            }

            if (Action.Equals("EditEntity"))
            {
                WISD.CarFriend.Model.CFModel.T_CF_OA_ReturnVisit model = new Model.CFModel.T_CF_OA_ReturnVisit();
                model.ReturnVisitID = Main;
                model.ConsumeID = ConsumeID;
                model.IsComplaint = Satisfaction == 0 ? 1 : Satisfaction;
                model.ReturnVisitType = ReturnVisitType;
                model.StartTime = StartTime;
                model.EndTime = EndTime;
                model.Complaint = Complaint;
                model.Result = Result;
                model.Satisfaction = Satisfaction;
                model.Memo = Memo;
                model.State = State;
                model.SendEmployee = SendEmployee;
                model.Reviser = Reviser;
                model.ReviseDate = ReviseDate;
                model.Memo1 = "";
                model.Memo2 = "";
                model.Memo3 = "";
                model.Memo4 = "";
                model.Memo5 = "";
                model.Memo6 = "";
                model.Memo7 = "";
                model.Memo8 = "";

                if (BLL.OA.ReturnVisitModule.EditEntity(model).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (Action.Equals("Init"))
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.GetData(PageSize, PageIndex, Condition));
                context.Response.End();
            }

            if (Action.Equals("GetOne"))
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.GetOne(Main.ToString()));
                context.Response.End();
            }

            if (Action.Equals("GetCardInfo"))
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.GetCardInfo(MemberID));
                context.Response.End();
            }

            if (Action.Equals("GetEp"))
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.GetEp());
                context.Response.End();
            }

            if (Action == "GetMemberInfo")
            {
                context.Response.Write(BLL.OA.ReturnVisitModule.GetMemberInfo(PageSize, PageIndex, Condition));
                context.Response.End();
            }
            if (Action == "GetUpdateLog")
            {
                var ReturnID = NullHelper.NullProcess<string>(context.Request["ReturnVisitID"], "");
                context.Response.Write(BLL.OA.ReturnVisitModule.GetUpdateLog(ReturnID));
                context.Response.End();
            }
        }


        /// <summary>
        /// IsReusable
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}